package gov.nasa.anml.utility;

import static java.lang.Math.*;


// mutable floats
// but using these as keys in a hashtable requires not changing the value
// i.e., be careful!
public class SimpleFloat implements SimpleObject<SimpleFloat> {

	public float v;

	public SimpleFloat() {
		v = 0;
	}

	public SimpleFloat(float v) {
		this.v = v;
	}

	public int hashCode() {
		return Float.floatToIntBits(v);
	}

	public boolean equals(Object obj) {
		if (obj instanceof SimpleFloat
				&& v == ((SimpleFloat) obj).v)
			return true;
		return false;
	}
	
	public boolean equals(SimpleFloat obj) {
		if (v == obj.v)
			return true;
		return false;
	}
	
	public SimpleFloat clone() {
		try {
			return (SimpleFloat) super.clone();
		} catch (CloneNotSupportedException e) {
			// assert false;
		}
		return null;
	}

	public int compareTo(SimpleFloat o) {
		if (this == null || o == null)
			return 1;
		return (int) signum(v - o.v);
	}
	
	public int compareTo(SimpleObject<SimpleFloat> o) {
		SimpleFloat f = (SimpleFloat) o;
		if (this == null || f == null)
			return 1;
		return (int) signum(v - f.v);
	}

	public String toString() {
		return Float.toString(v);
	}

	public void assign(SimpleFloat c) {
		v = c.v;
	}
	
	public void assign(float v) {
		this.v = v;
	}

	public SimpleFloat value() {
		return this;
	}
}
